/*
 * Created by Christopher King
 * Copyright (C) 2007 Christopher King, All Rights Reserved.
 */
package us.cirion.adventure.engine.result;

import java.util.Enumeration;

import us.cirion.adventure.engine.GameDisplay;
import us.cirion.adventure.engine.Noun;
import us.cirion.adventure.engine.Player;
import us.cirion.adventure.engine.Result;

/**
 * DisplayInventory is an action that will list all the items in a player's
 * inventory, or a suitable message if the inventory is empty.
 * 
 * @author Chris
 */
public class DisplayInventory implements Result
{

	private GameDisplay display;
	private Player player;

	/**
	 * Construct a new DisplayInventory result.
	 * @param display The display used to show the inventory.
	 * @param player The character whose inventory should be displayed.
	 */
	public DisplayInventory(GameDisplay display, Player player)
	{
		this.display = display;
		this.player = player;
	}

	/**
	 * Construct and display information about the player's inventory.
	 */
	public void execute()
	{
		Enumeration items = player.getItems();
		String message = null;
		if (!items.hasMoreElements())
		{
			// TODO: This should be configureable and optional; fall back on a
			// default if missing.
			message = "You are carrying nothing.";
		} else
		{
			StringBuffer messageBuilder = new StringBuffer("You are carrying: ");
			while (items.hasMoreElements())
			{
				Noun item = (Noun) items.nextElement();
				messageBuilder.append('\n');
				messageBuilder.append(item.getDescription().toString());
			}
			message = messageBuilder.toString();
		}
		display.displayMessage(message);
	}

}
